package com.mymain.demo.service;

import com.mymain.demo.entity.User;
import com.mymain.demo.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/**
 * Author : JiangLinHan
 * Date : 2019/4/10
 * Time : 9:25
 * 左下角两个加v ： 快速返回变量
 **/
@Transactional
@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
        List<User> userList = userMapper.findAll();
        return userList;
    }

    @Override
    public List<User> findAllByIdAfter(Integer num) {
        return userMapper.findAllByIdAfter(num);
    }

    @Override
    public void save(User user) {
        userMapper.save(user);
    }

    /**
     * 通过id删除user
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        userMapper.deleteById(id);
    }

    /**
     * 通过id查询user
     * @param id
     * @return
     */
    @Override
    public User findAllById(Integer id) {
        return userMapper.findAllById(id);
    }

    /**
     * 修改
     * @param user
     */
    @Override
    public void update(User user) {
        userMapper.save(user);
    }

    /**
     * 通过username查询user
     * @param username
     * @return
     */
    @Override
    public User findUserByUsername(String username) {
        return userMapper.findUserByUsername(username);
    }
}
